<%--
  @author Nuwan Koggalahewa
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<script src="${pageContext.request.contextPath}/js/printer.js" type="text/javascript"></script>
<%--<link rel="stylesheet" href="${pageContext.request.contextPath}/css/printDetailForm.css" media="print"/>--%>

<script type="text/javascript">
    $(function () {
        var d = new Date();
        var n = d.getFullYear();
        var options = "";
        for(var i=n; i > 1950; --i){
            options += '<option value="'+i+'">'+i+'</option> ' ;
        }
        $("#yearPicker").html(options)  ;

    });

    $(function () {
        var numbers = ['Annually', 'Semi-Annually', 'Quarterly', 'Monthly'];

        var options = "";
        for(var i=0; i < numbers.length; ++i){
            options += '<option value="'+i+'">'+numbers[i]+'</option> ' ;
        }
        $("#modePicker").html(options)  ;

        $('input#submit').click(function (evt1) {
            var year = $("select#yearPicker").attr("value");
            var mode = $("select#modePicker").attr("value");
            var track = $("select#railwayTrackId").attr("value");
            var district = $("select#districtId").attr("value");
            var type = "IncomeReport";
            $('div#result-table').html('');
            $.getJSON('${pageContext.request.contextPath}/common/RailwayReportService', {type: type, year: year, mode: mode, track: track, district: district},
                    function (data) {
                        var quartile = data['IncomeData'];
                        for(var a in quartile){
                            if (isNaN(a)) continue;
                            var tData = quartile[a];
                            var html = '<h2></h2>'
                            html +='<table class="width-100 margin-10-auto table land-table"><thead><tr><th>District</th><th>Amount</th><th>Vat</th></tr></thead>';
                            html +='<tbody>';
                            for (var b in tData) {
                                if (tData.hasOwnProperty(b)) {
                                    html +='<tr><td>'+b+'</td><td>'+resolveAmountValue(tData[b][0][0])+'</td><td>'+resolveAmountValue(tData[b][0][1])+'</td></tr>';
                                }
                            }
                            html +='</tbody><table>';
                            $('div#result-table').append(html);
                            formatTables();
                        }
                    });
        });

        $('select#railwayTrackId').bind('change', function (evt1) {
            var id = $("select#railwayTrackId").attr("value");
            if(id>0){
                $.getJSON('${pageContext.request.contextPath}/common/DivisionLookupService', {id: id, mode: 6},
                    function (data) {
                        var options1 = '<option value="0">' + $('#all').val() + '</option> ';
                        var ds = data.districtList;
                        for (var i = 0; i < ds.length; i++) {
                            options1 += '<option value="' + ds[i].optionValue + '">' + ds[i].optionDisplay + '</option>'
                        }
                        $("select#districtId").html(options1);
                    });
            }else{
                $("select#districtId").html('<option value="0">' + $('#all').val() + '</option> ');
            }
        });
    });

    function resolveAmountValue(data){
        var val = 0;
        if (data != null && data !== undefined) {
            val = parseInt(data);
        }
        return val.toFixed(2);
    }

    function formatTables(){
            $('.land-table').dataTable({
            "sPaginationType":"full_numbers",
            "bDestroy":true,
            "oLanguage":{
                "sZeroRecords":$('#no-record').val(),
                "sLengthMenu":$('#display').val() + " _MENU_ " + $('#records').val(),
                "sSearch":$('#search').val(),
                "sInfo":$('#showing').val() + " _START_ " + $('#to').val() + " _END_ " + $('#of').val() + " _TOTAL_ " + $('#entries').val(),
                "sInfoEmpty":$('#no-record').val(),
                "oPaginate":{
                    "sFirst":$('#first').val(),
                    "sLast":$('#last').val(),
                    "sNext":$('#next').val(),
                    "sPrevious":$('#previous').val()
                }
            },
            "fnDrawCallback":function () {
                if ($('.dataTables_paginate span span.paginate_button').size()) {
                    $('.dataTables_paginate')[0].style.display = "block";
                } else {
                    $('.dataTables_paginate')[0].style.display = "none";
                }
            }
        });
    }



</script>


<div id="land-registration-module-home-title" class="module-home-title">
    <s:a href="reportModule.do">
        <span><img src="${pageContext.request.contextPath}/images/print.png" alt="Print">
            <s:label value="%{getText('reports.label')}"/></span>
    </s:a>
    <span class="module-title-breaker"> > </span>
    <s:a href="totalIncomeReport.do">
        <span><img src="${pageContext.request.contextPath}/images/list.png" alt="Detailed All Land Report">
            <s:label value="Total Income Report"/></span>
    </s:a>
    <div id="back-button" align="right">
        <s:form><s:submit value="%{getText('back_btn.label')}" action="reportModule"/></s:form>
    </div>
</div>

<div id="printbtn" class="form-button-div right-align">
<input type="button" style="margin:10" id="printBtnId" value="Print" onclick="printPage('init-land-report-list', 'A4', 'P');"/>
</div>

<div id="init-land-report-list">
    <div class="page-title center-align">
        <h2><s:label value="%{getText('total_income_report.label')}"/></h2>
    </div>
    <table class="width-635-px margin-10-auto" id="filter-lists">

        <tr>
            <td><s:label value="Year"/></td>
            <td><s:label value="Report Type"/></td>
        </tr>
        <tr>
            <td class="center-align">
                <s:if test="%{railwayTrackList.size==1}">
                    <s:select id="yearPicker" name="yearId" list="districtList"  cssClass="width-250-px"/>

                </s:if>
                <s:else>
                    <s:select id="yearPicker" name="yearId"  list="districtList" headerKey="0"
                              headerValue="%{getText('all.label')}" cssClass="width-250-px"/>
                </s:else>
            </td>
            <td class="center-align">
                <s:if test="%{districtEngineerZoneList.size==1}">
                    <s:select id="modePicker" name="modeId" list="districtList" cssClass="width-250-px"/>
                </s:if>
                <s:else>
                    <s:select id="modePicker" name="modeId" list="districtList" headerKey="0"
                              headerValue="%{getText('all.label')}" cssClass="width-250-px"/>
                </s:else>
            </td>
        </tr>


        <tr>
            <td><s:label value="Railway Line"/></td>
            <td><s:label value="%{getText('district.label')}"/></td>
        </tr>
        <tr>
            <td class="center-align">
                <s:select id="railwayTrackId" name="railwayTrackId" list="railwayTrackList" headerKey="0"
                              headerValue="%{getText('all.label')}" cssClass="width-250-px"/>
            </td>
            <td class="center-align">
                <select id="districtId" name="districtName" class="width-250-px"><option value="0"><s:property value="%{getText('all.label')}"/></option></select>
            </td>
        </tr>


        <tr>
            <td class="left-align margin-top-30px" >
                <s:submit value="Submit Query" id="submit"></s:submit>
            </td>
        </tr>
        </table>
    <div id="result-table">

    </div>
</div>

<%-- <table id="land-table" class="width-100 margin-10-auto margin-top-30px  table land-table" >
    <thead>
    <tr>
        <th><s:label value="Month"/></th>
        <th><s:label value="District"/></th>
        <th><s:label value="Railway Line"/></th>
        <th><s:label value="Total Rental(Rs)"/></th>
        <th><s:label value="Total Tax(Rs)"/></th>
        <th><s:label value="Total Income(Rs)"/></th>

    </tr>
    </thead>
    <tbody>
     <tr >
         <td style="text-align: center">January</td>
         <td style="text-align: center">Colombo</td>
         <td style="text-align: center">Main Line</td>
         <td style="text-align: center">1,020,000.00</td>
         <td style="text-align: center">20,000.00</td>
         <td style="text-align: center">1,000,000.00</td>

     </tr>

    <s:iterator status="lands" value="landList">

        <tr>
                &lt;%&ndash;<td width="130px"><s:if test="referenceNumber > 0"><s:property
                        value="referenceNumber"/></s:if><s:else><s:label
                        value="%{getText('undefined.label')}"/></s:else></td>&ndash;%&gt;
            <td width="80px"><s:property value="id"/></td>
            <td><s:property value="nameOfTheLand"/></td>
            <td width="80px"><s:property value="planNumber"/></td>
            <td width="80px"><s:property value="lotNumber"/></td>
            <td width="180px">
                <s:if test="alienationState.ordinal() == 0">
                    <s:if test=" language=='si' ">
                        <s:property value="@lk.icta.common.AppConstants@UN_ALIENATED_SI"/>
                    </s:if>
                    <s:else>
                        <s:property value="alienationState"/>
                    </s:else>

                </s:if>
                <s:elseif test="alienationState.ordinal() == 1">
                    <s:if test=" language=='si' ">
                        <s:property value="@lk.icta.common.AppConstants@UN_ALIENATED_SI"/>
                    </s:if>
                    <s:else>
                        <s:property value="alienationState"/>
                    </s:else>

                </s:elseif>
                <s:else>
                    <s:property value="alienationState"/>
                </s:else>

            </td>
            <td>
                <s:property value="approvalState"/>

            </td>
            <td width="80px" class="center-align"><a href="#" title="View" id="viewLink"
                                                     onclick="viewLandDetails('<s:property value="id"/>')">
                <img src="${pageContext.request.contextPath}/images/detailed-form.png"
                     style="border:none; width:25px; height:25px;"/> </a></td>
        </tr>

    </s:iterator>
    </tbody>
</table>           --%>


<%--<s:include value="../printCaller.jsp"/>--%>
<%--<div id="printDivId">

    <div id="init-land-report-list">
        <div class="page-title center-align">
            <h2><s:label value="%{getText('detailed_lands_report.label')}"/></h2>
        </div>
        <table class="width-635-px margin-10-auto" id="filter-lists">
            <tr>
                <td><s:label value="aaaaaaa"/></td>
                <td><s:label value="%cccc"/></td>
            </tr>
            <tr>
                <td class="center-align">
                  &lt;%&ndash;  <s:if test="%{provinceList.size==1}">
                        <s:select id="provinceId" name="provinceId" list="" cssClass="width-250-px"/>
                    </s:if>
                    <s:else>
                        <s:select id="provinceId" name="provinceId" list="" headerKey="0"
                                  headerValue="%{getText('all.label')}" cssClass="width-250-px"/>
                    </s:else>&ndash;%&gt;
                </td>
                <td class="center-align">
                   &lt;%&ndash; <s:if test="%{districtList.size==1}">
                        <s:select id="districtId" name="districtName" list="" cssClass="width-250-px"/>
                    </s:if>
                    <s:else>
                        <s:select id="districtId" name="districtName" list="" headerKey="0"
                                  headerValue="%{getText('all.label')}" cssClass="width-250-px"/>
                    </s:else>&ndash;%&gt;
                </td>
            </tr>
            <tr>
                <td><s:label value="%{getText('ds_division.label')}"/></td>
                <td><s:label value="%{getText('gn_division.label')}"/></td>
            </tr>
            <tr>
                <td class="center-align">
                    &lt;%&ndash;<s:if test="%{dsDivisionList.size==1}">
                        <s:select id="dsDivisionId" name="dsDivisionId" list="" cssClass="width-250-px"/>
                    </s:if>
                    <s:else>
                        <s:select id="dsDivisionId" name="dsDivisionId" list="" headerKey="0"
                                  headerValue="%{getText('all.label')}" cssClass="width-250-px"/>
                    </s:else>&ndash;%&gt;
                </td>
                <td class="center-align">
                    <s:select id="gnDivisionId" name="gnDivisionId" list="" headerKey="0"
                              headerValue="%{getText('all.label')}" cssClass="width-250-px"/></td>
            </tr>
            &lt;%&ndash;<tr>
                <td><s:label value="%{getText('alienation_state.label')}"/></td>
                <td><s:label value="%{getText('alienation_method.label')}"/></td>

            </tr>
            <tr>
                <td><s:select id="alienationState" name="alienationState"
                              list="alienationStatesList" headerKey="0"
                              headerValue="%{getText('select.label')}"
                              onChange="loadAlienation()" cssClass="width-250-px"/>

                </td>
                <td><s:select list="alienationTypeList" name="alienationType"
                              id="alienationType"
                              headerKey="0"
                              disabled="true"
                              headerValue="%{getText('all.label')}"
                              cssClass="width-250-px"/></td>

            </tr>
            <tr>
                <td colspan="2"><s:label value="%{getText('geological_type.label')}"/></td>
            </tr>
            <tr>
                <td><s:select id="geologicalTypeId" name="land.geologicalType.id"
                              list="geologicalTypeList" headerKey="0"
                              headerValue="%{getText('select.label')}" cssClass="width-250-px"/></td>
                <td><s:submit onclick="generateReport()" id="gen-report"
                              value="%{getText('gen_report.label')}"/></td>
            </tr>&ndash;%&gt;
        </table>
        <div id="report-header">
            <table class="width-100 margin-10-auto">
                <tr>
                    <td><s:label value="%{getText('district.label')}"/> : <s:textfield id="district"
                                                                                       cssStyle="border:none; background: none; color: #000;"
                                                                                       disabled="true"/></td>
                </tr>
                <tr>
                    <td><s:label value="%{getText('ds_division.label')}"/> : <s:textfield id="ds-name"
                                                                                          cssStyle="border:none; background: none; color: #000;"
                                                                                          disabled="true"/></td>
                </tr>
                <tr>
                    <td><s:label value="%{getText('gn_division.label')}"/> : <s:textfield id="gn-name"
                                                                                          cssStyle="border:none; background: none; color: #000;"
                                                                                          disabled="true"/></td>
                </tr>
            </table>
        </div>


        <div id="land-list">


            <table class="width-100 margin-10-auto table land-table" id="land-report" border="1" cellpadding="0"
                   cellspacing="0">

          &lt;%&ndash;  </table>
            <div id="nextPreId" align="right">
                <img onclick="previous();" id="previousId" src="${pageContext.request.contextPath}/images/previous.gif"
                     border="none"/>
                <img onclick="next();" id="nextId" src="${pageContext.request.contextPath}/images/next.gif"
                     border="none"/>
            </div>&ndash;%&gt;


        </div>

    </div>
</div>--%>

<%-- Localization text for java script generated text --%>

<s:hidden id="ref" value="%{getText('reference_no.label')}"/>
<s:hidden id="dsDiv" value="%{getText('ds_division.label')}"/>
<s:hidden id="gnDiv" value="%{getText('gn_division.label')}"/>
<s:hidden id="lname" value="%{getText('name_of_the_land.label')}"/>
<s:hidden id="plan" value="%{getText('plan_no.label')}"/>
<s:hidden id="lot" value="%{getText('lot_no.label')}"/>
<s:hidden id="ext_pec" value="%{getText('extent_perches.label')}"/>
<s:hidden id="ext_hec" value="%{getText('extent_hectare.label')}"/>
<s:hidden id="all" value="%{getText('all.label')}"/>

<s:hidden id="display" value="%{getText('display.label')}"/>
<s:hidden id="records" value="%{getText('records.label')}"/>
<s:hidden id="search" value="%{getText('search.label')}"/>
<s:hidden id="no-record" value="%{getText('no_record.label')}"/>
<s:hidden id="showing" value="%{getText('showing.label')}"/>
<s:hidden id="to" value="%{getText('to.label')}"/>
<s:hidden id="of" value="%{getText('of.label')}"/>
<s:hidden id="entries" value="%{getText('entries.label')}"/>
<s:hidden id="first" value="%{getText('first.label')}"/>
<s:hidden id="last" value="%{getText('last.label')}"/>
<s:hidden id="next" value="%{getText('next.label')}"/>
<s:hidden id="previous" value="%{getText('previous.label')}"/>


<s:hidden id="report-title" value="%{getText('land_list_by_gn_division.label')}"/>
<s:hidden id="print" value="%{getText('print.label')}"/>
